#pragma once

#include <engine.core/qt_hash.hpp>

#include "Compiler.hpp"
#include "Project.hpp"
#include "ScriptEditWindow.hpp"




namespace Engine
{
	namespace Edit
	{
		/**
		 * This class exposes all reflection information from the angelscript system
		 * to the application.
		 * In the end, it shall offer a similar functionality to intellisense.
		 */
		class AutoCompletion
			: public QObject
		{
			Q_OBJECT

		public:

			typedef Compiler::Types                                 Types;
			typedef std::vector<Compiler::Compilation>              Compilations;
			typedef boost::unordered_map<QString,ErrorModel::ptr>   Errors;

			SHARED(AutoCompletion);



			AutoCompletion();
			virtual ~AutoCompletion();



			/**
			 * Sets the current project for use in AutoCompletion.
			 */
			void setProject(Project::ptr project);

		public slots:

			/**
			 * This slot is called whenever a ScriptEditWindow is opened.
			 */
			void scriptWindowOpened(const ScriptEditWindow* window);

			/**
			 * This slot is called whenever a ScriptEditWindow is changed.
			 */
			void scriptWindowChanged(const ScriptEditWindow* window);

			/**
			 * This slot is called whenever a ScriptEditWindow is closed.
			 */
			void scriptWindowClosed(const ScriptEditWindow* window);

		protected slots:

			void timer();

		protected:

			void compiled(CompilationResult result);

		private:

			Project::ptr        m_project;
			Compiler::Scripts   m_contents;     //< The current contents of all scripts
			Compilations        m_compilations; //< All ongoing compilations

			Types               m_types;        //< All ObjectTypes, defined in the scripts

			Errors              m_errors;

			Compiler            m_compiler;
			QTimer              m_timer;

			std::size_t         m_changes;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
